<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>团体票追加乘客</title>
    </head>
    <body>
        <div id="add_group_passenger_div">
        </div>
        <script>
            var addGroupPass_order_id = "<%=@orderid%>";
            var addGroupPass_seat = "<%=@pass_num%>";
            var passStr = "";
            Ext.onReady(function(){
                var num = 1;
                var myData = [];
                var store = new Ext.data.SimpleStore({
                    fields: ['id','name','human_type','card','birthday','insurance_number']
                });
                //store.loadData(myData);
                var groupPassGrid = new Ext.grid.GridPanel({
                    store: store,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    //stripeRows: true,
                    height: 350,
                    columns: [{
                            header: "序号",
                            width: 60,
                            sortable: true,
                            dataIndex: 'id'
                        }, {
                            header: "乘客姓名",
                            width: 100,
                            sortable: true,
                            dataIndex: 'name'
                        }, {
                            header: "类型",
                            width: 60,
                            sortable: true,
                            dataIndex: 'human_type'
                        }, {
                            header: "证件号",
                            width: 180,
                            sortable: true,
                            dataIndex: 'card'
                        }, {
                            header: "出生日期",
                            width: 100,
                            sortable: true,
                            dataIndex: 'birthday'
                        }, {
                            header: "保险",
                            width: 50,
                            sortable: true,
                            dataIndex: 'insurance_number'
                        }]

                });

                var seatNumber = new Ext.form.TextField({
                    fieldLabel: '座位数',
                    name: 'seat_number',
                    anchor: '90%',
                    value: addGroupPass_seat,
                    readOnly: true
                });
                //常旅客关键字搜索
                var pass_resultTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '<h3>{name} {card}</h3>', '</div></tpl>');
                var passengerName = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: "/customers/getPassengerComboBox"
                        }),
                        reader: new Ext.data.JsonReader({
                            root: 'root'
                        }, ['name','phone','card'])
                    }),
                    fieldLabel: '乘客姓名',
                    name: 'pessenger_name',
                    allowBlank: false,
                    blankText: "乘客姓名不允许为空",
                    //displayField: 'name',
                    typeAhead: false,
                    loadingText: '正在查找...',
                    //width: 230,
                    anchor: '90%',
                    //hideTrigger: true,
                    tpl: pass_resultTpl,
                    minChars: 0,
                    itemSelector: 'div.search-item',
                    onSelect: function(record){
                        passengerName.setValue(record.data.name);
                        card.setValue(record.data.card);
                        if (this.isExpanded()) {
                            this.collapse();
                        }
                    }
                });
                var card = new Ext.form.TextField({
                    fieldLabel: '证件号码',
                    name: 'card',
                    anchor: '90%'
                });
                var birthday = new Ext.form.DateField({
                    fieldLabel: '生日',
                    name: 'birthday',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: true,
                    blankText: "出生日期必须选择",
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    //anchor: '50%'
                    width: 90
                });
                var ageType = new Ext.form.ComboBox({ //combobox
                    name: 'age_type',
                    fieldLabel: '类型',
                    resiable: true,
                    typeAhead: true,
                    handleHeight: 100,
                    displayField: 'value',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    width: 60,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    value: "成人",
                    store: new Ext.data.Store({
                        reader: new Ext.data.ArrayReader({}, ['value']),
                        data: [['成人'], ['儿童']]
                    }),
                    listeners: {
                        select: function(combo, record, index){
                            if (record.data.value == "成人") {
                                birthday.disable();
                                birthday.allowBlank = true;
                                card.enable();
                            }
                            else {
                                birthday.enable();
                                birthday.allowBlank = false;
                                card.setValue('');
                                card.disable();
                            }
                        }
                    }
                });
                var insurance = new Ext.form.ComboBox({ //combobox
                    name: 'insurance',
                    fieldLabel: '保险',
                    resiable: true,
                    typeAhead: true,
                    handleHeight: 100,
                    displayField: 'value',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    width: 60,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    value: 0,
                    store: new Ext.data.Store({
                        reader: new Ext.data.ArrayReader({}, ['value']),
                        data: [['0'], ['1'], ['2']]
                    })
                });

                var addButton = new Ext.Button({
                    text: '添加',
                    handler: function(){
                        if (addGroupPassengersFormPanel.form.isValid()) {
                            if (num>parseInt(addGroupPass_seat)){
                                //alert(passStr);
                                Ext.MessageBox.alert('提示', '乘客数已满');
                            }else{
                                var birthday_par = "";
                                if (birthday.getValue()!=""){
                                    birthday_par = birthday.getValue().format('Y-m-d');
                                }
                                if (passStr!=""){
                                    passStr += ";";
                                }
                                passStr += num+","+passengerName.getValue()+","+ageType.getValue()+","+card.getValue()+","+birthday_par+","+insurance.getValue();
                                //alert(myData);
                                myData.push([num, passengerName.getValue(), ageType.getValue(), card.getValue(), birthday_par, insurance.getValue()]);
                                //alert(myData);
                                store.loadData(myData);
                                num += 1;
                            }
                        }
                    }
                });
                var submitButton = new Ext.Button({
                    text: ' 提 交 ',
                    handler: function(){
                        if (num<=parseInt(addGroupPass_seat)){
                            Ext.MessageBox.alert('提示', '乘客信息没有填满');
                        }
                        else if (addGroupPassengersFormPanel.form.isValid()) {
                            var url = '/orders/saveGroupPassenger?orderid='+addGroupPass_order_id+'&passStr='+encodeURIComponent(passStr);
                            submitButton.setDisabled(true);
                            addGroupPassengersFormPanel.form.submit({
                                url: url,
                                waitMsg: '正在提交中......',
                                success: function(form, action){
                                    var info = "";
                                    if (action && action.result) {
                                        info = action.result.info;
                                    }
                                    else {
                                        info = '订票失败,具体失败原因请查询日志文件';
                                    }
                                    if (info.indexOf("成功") >= 0) {
                                        Ext.MessageBox.alert('操错成功', info);
                                    }
                                    else {
                                        Ext.MessageBox.alert('操作信息', info);
                                        submitButton.setDisabled(false);
                                    }
                                },
                                failure: function(form, action){
                                    Ext.MessageBox.alert('操作失败', '操作失败');
                                    submitButton.setDisabled(false);
                                }
                            });

                        }else{
                            Ext.MessageBox.alert('提示', '请填写必填信息后再提交');
                        }
                    }
                });
                var addGroupPassengersFormPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 60,
                    labelAlign: 'right',
                    frame: true,
                    width: '100%',
                    url: '/orders/saveGroupPassenger',
                    //params: paramStr,
                    //defaultType: 'textfield',
                    items: [groupPassGrid,{
                            layout: 'column',
                            border: false,
                            items: [{
                                    columnWidth: .2,
                                    layout: 'form',
                                    border: false,
                                    items: [seatNumber]
                                }]
                        }, {
                            id: 'div_passenger',
                            xtype: 'fieldset',
                            title: '常旅客信息',
                            collapsible: true,
                            autoHeight: true,
                            items: [{
                                    layout: 'column',
                                    border: false,
                                    id: 'div_passenger_1',
                                    items: [{
                                            columnWidth: .2,
                                            layout: 'form',
                                            border: false,
                                            items: [passengerName]
                                        }, {
                                            columnWidth: .25,
                                            layout: 'form',
                                            border: false,
                                            items: [card]
                                        }, {
                                            columnWidth: .15,
                                            layout: 'form',
                                            border: false,
                                            items: [ageType]
                                        }, {
                                            columnWidth: .2,
                                            layout: 'form',
                                            border: false,
                                            items: [birthday]
                                        }, {
                                            columnWidth: .2,
                                            layout: 'form',
                                            border: false,
                                            items: [insurance]
                                        }]
                                }]
                        }],
                    buttons: [addButton,submitButton]
                });
                addGroupPassengersFormPanel.render('add_group_passenger_div');

            });


        </script>
    </body>
</html>
